package com.uenpay.im.ui.old.activity.company;

import com.uenpay.im.configuration.APIConfiguration;
import com.uenpay.im.entities.HttpInvokeResult;
import com.uenpay.im.invokeitems.BaseHttpInvokeItem;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * @author SL
 * @created 2016-2-22 下午3:52:22
 * @copyRight http://www.qiyunxin.com
 * @function 添加员工到部门
 */
public class AddEmployeeInvokeItem extends BaseHttpInvokeItem {

	public class AddEmployeeInvokeItemResult extends HttpInvokeResult {
	}

	public AddEmployeeInvokeItemResult getOutPut() {
		return (AddEmployeeInvokeItemResult) GetResultObject();
	}

	/**
	 * 添加员工到部门
	 * 
	 * @param departid
	 *            部门id
	 * @param entid
	 *            企业id
	 * @param mobile
	 *            手机号
	 * @param nickname
	 *            名称
	 * @param position
	 *            职位
	 */
	public AddEmployeeInvokeItem(int departid, int entid, String mobile,
			String nickname, String position) {
		String url = APIConfiguration.getBaseUrl()
				+ "Organization/Organization/addEntCust?departid=" + departid
				+ "&entid=" + entid + "&mobile=" + mobile + "&nickname="
				+ nickname + "&position=" + position + "&"
				+ APIConfiguration.getCustIdAndToken();
		SetUrl(url);
	}
	
	/**
	 * 修改员工信息
	 * @param custid
	 * @param departid
	 * @param entid
	 * @param position
	 * @param nickname
	 */
	public AddEmployeeInvokeItem(String custid,int departid,int entid,String position,String nickname){
		String url = APIConfiguration.getBaseUrl()
				+ "Organization/Organization/updateEntCust?custid=" + custid
				+ "&departid=" + departid + "&entid=" + entid + "&position="
				+ position + "&nickname=" + nickname + "&"
				+ APIConfiguration.getCustIdAndToken();
		SetUrl(url);
	}

	@Override
	protected Object DeserializeResult(String responseBody) {
		AddEmployeeInvokeItemResult result = new AddEmployeeInvokeItemResult();
		try {
			JSONObject json = new JSONObject(responseBody);
			result.status = json.optInt("status");
			result.msg = json.optString("msg");
		} catch (JSONException e) {
			e.printStackTrace();
			return result;
		}

		return result;
	}

}
